<?php

namespace catchAdmin\system\controller;

use app\common\lib\Redis;
use app\common\lib\ZhyxMongo;
use catcher\base\CatchRequest as Request;
use catcher\CatchResponse;
use catcher\base\CatchController;
use think\model\concern\SoftDelete;
use think\Response;

class PhoneRecord extends CatchController
{


    protected \app\common\model\PhoneRecord $phoneRecordModel;

    /**
     *
     * @time 2023/12/13 11:10
     * @param \app\common\model\PhoneRecord $phoneRecordModel
     */
    public function __construct(\app\common\model\PhoneRecord $phoneRecordModel)
    {
        $this->phoneRecordModel = $phoneRecordModel;

    }

    /**
     *
     * @time 2023/12/13 11:10
     * @return Response
     */
    public function index(): Response
    {
        return CatchResponse::paginate($this->phoneRecordModel->getList());
    }


    /**
     *
     * @time 2023/12/13 11:10
     * @param $id
     * @param Request $request
     * @return Response
     */
    public function update($id, Request $request): Response
    {
        $phoneRecordInfo = (new \app\common\model\PhoneRecord())->where([["id", "=", $id], ["status", "=", 0]])->find();

        if (empty($phoneRecordInfo)) {
            return CatchResponse::success([],"没有更新的数据");
        }

        $postData = $request->post();
        $result = $phoneRecordInfo->save($postData);
        if($result!==false){
            //执行最近一个月的当前患者修改成已处理
            (new \app\common\model\PhoneRecord())->where([["mobile","=",$phoneRecordInfo["mobile"]],["status","=",0],["created_at",'between',[strtotime('-1 month'),time()]]])->save(["status"=>1]);

        }
        return CatchResponse::success($result);
    }


}